package Homework3;

interface IShape {
    double area();
    square zoom(double factor);
}

class square implements IShape
{
    private double sideL;

    square(double n)
    {
        if (n <= 0)
        {
            System.out.println("边长必须为正数");
        }
        this.sideL = n;
    }

    @Override
    public double area() {
        return sideL*sideL;
    }

    @Override
    public square zoom(double factor) {
        if (factor <= 0)
        {
            System.out.println("factor必须为正数");
        }
        double newarea = this.area()*factor;
        double newsideL = Math.sqrt(newarea);
        return new square(newsideL);
    }

    @Override
    public String toString(){
        return String.format("正方形的边长: %.2f; 正方形的面积: %.2f", this.sideL, this.area());
    }
}

public class SquareTest {
    public static void main(String[] args) {
        square s = new square(10);
        System.out.println(s.toString());

        square s1 = s.zoom(0.25);
        System.out.println(s1.toString());
    }
}
